#! /home/wangdy/miniconda3/bin/python
# -*- coding: UTF-8 -*-

# FileName     : __init__
# Author       : EastsunW eastsunw@foxmail.com
# Create at    : 2022-04-22 17:52
# Last Modified: 2022-04-22 17:52
# Modified By  : EastsunW
# -------------
# Description  : 一个app的工厂函数
# -------------

from flask import Flask
from .Configs import configs
from .Utils import mongo

# 导入视图，前后端分离的项目这块不需要更改
from .Views import views

# NOTE 在这里添加所有的API模块的蓝图对象，首字母大写，以_BP结尾
from .Services.FIMO import Query_FIMO_BP
from .Services.Hint import Hint_BP
# from .Services.Hint import Hint_BP, Hint_MNV_BP, Hint_TF_BP, Hint_Gene_BP
from .Services.PWM import PWM_BP
from .Services.Predict import Predict_BP
from .Services.Download import Download_BP


def create_app(config_name):
    """创建app"""
    app = Flask(
        __name__,
        template_folder="Templates",
        static_folder="Static",
        static_url_path='',
    )
    # 导入设置
    app.config.from_object(configs.get(config_name))

    mongo.init_app(app)
    app.register_blueprint(views, url_prefix="/")
    app.register_blueprint(Query_FIMO_BP, url_prefix="/api")
    app.register_blueprint(Hint_BP, url_prefix="/api")
    # app.register_blueprint(Hint_MNV_BP, url_prefix="/api")
    # app.register_blueprint(Hint_TF_BP, url_prefix="/api")
    # app.register_blueprint(Hint_Gene_BP, url_prefix="/api")
    app.register_blueprint(PWM_BP, url_prefix="/api")
    app.register_blueprint(Predict_BP, url_prefix="/api")
    app.register_blueprint(Download_BP, url_prefix="/api")

    return app
